package main;

import gui.DateWindow;
import gui.mainWindow.MainWindow;
import java.io.*;

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import questions.Questions;
import utils.DateUtils;


public class Domandino
{
	static File progress = new File("progress.txt");
	static File questions = new File("questions.txt");
	static Questions myQueue;
	private static DateWindow dateW;
	private static MainWindow mainW;
	
	public static void main(String[] args){
		start();
	}
	
	public static void start(){
		
		for( LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()){
			if(info.getName().equals("GTK+")){
				try {
					UIManager.setLookAndFeel(info.getClassName());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			else if(info.getName().equals("Nimbus")){
				try {
					UIManager.setLookAndFeel(info.getClassName());
					break;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		dateW = new DateWindow();
	 			
	 	//controlla e in caso aggiorna la data
	 	if(!DateUtils.existsDate()){
	 		dateW.setVisible(true);
	 		dateW.waitFor();
	 	}else{
	 		try {
				DateUtils.loadDate();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
				System.exit(0);
			}
	 	}
	 	
	 	myQueue = new Questions();
	 	mainW = new MainWindow(myQueue);
	 	mainW.setDate(DateUtils.getDate());
	 	mainW.showMenuPanel();	 	
	 	mainW.setVisible(true);
	}

	public static void restart(){
		myQueue = null;
		dateW.dispose();
		mainW.dispose();
		start();
		
	}
}
